package utility;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

import controller.bulkUpload.BulkUploadController;

import dto.search.ProfileDTO;

import entity.Profile;

public class BulkUpload {

	public static void main(String[] args)
    {
        try
        {
            FileInputStream file = new FileInputStream(new File("C:\\Users\\bonamahe\\Desktop\\profileData.xls"));
 
            //Create Workbook instance holding reference to .xlsx file
            HSSFWorkbook workbook = new HSSFWorkbook(file);
 
            //Get first/desired sheet from the workbook
            HSSFSheet sheet = workbook.getSheetAt(0);
 
            //Iterate through each rows one by one
            Iterator<Row> rowIterator = sheet.iterator();
            List<ProfileDTO> profileList=new ArrayList<ProfileDTO>();
            while (rowIterator.hasNext())
            {
                Row row = rowIterator.next();
                ProfileDTO dto=new ProfileDTO();
                //For each row, iterate through all the columns
                dto.setTenantid(row.getCell(1).toString());
                dto.setFirstname(row.getCell(2).toString());
                dto.setLastname(row.getCell(3).toString());
                dto.setGender(row.getCell(4).toString());
//                dto.setDob(row.getCell(5).toString());
              //  dto.setAge(row.getCell(6).toString());
                dto.setBirthplace(row.getCell(7).toString());
                dto.setHeight(Integer.parseInt(row.getCell(8).toString()));
                dto.setComplexion(row.getCell(9).toString());
                dto.setEducationlevel(row.getCell(10).toString());
                dto.setEducation(row.getCell(11).toString());
                dto.setMaritalstatus(row.getCell(12).toString());
                dto.setPaternalgotram(row.getCell(13).toString());
                dto.setMaternalgotram(row.getCell(14).toString());
                dto.setStar(row.getCell(15).toString());
                dto.setRasi(row.getCell(16).toString());
                dto.setAboutself(row.getCell(17).toString());
                dto.setOccupation(row.getCell(18).toString());
                dto.setIncome(row.getCell(19).toString());
                dto.setFathername(row.getCell(20).toString());
                dto.setFatherprofession(row.getCell(21).toString());
                dto.setMothername(row.getCell(22).toString());
                dto.setMotherprofession(row.getCell(23).toString());
                dto.setEmail(row.getCell(24).toString());
                dto.setMobileno(row.getCell(25).toString());
                dto.setAddress(row.getCell(26).toString());
                profileList.add(dto);
                
//                System.out.println("");
            }
            file.close();
            BulkUploadController controller=new BulkUploadController();
            controller.upload(profileList);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}
